import { createStore, applyMiddleware } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
import thunk from 'redux-thunk'
import { combineReducers } from 'redux'

import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';

import userstore from '../pages/login/store/userreducer'
import newhomestore from '../pages/Newhome/store/reducer'

const persistConfig = {
    key: 'root',
    storage: storage,
    stateReconciler: autoMergeLevel2 // 查看 'Merge Process' 部分的具体情况
};

const reducer = combineReducers({ userstore, newhomestore })
const persistedReducer = persistReducer(persistConfig, reducer);
export const store = createStore(persistedReducer, composeWithDevTools(applyMiddleware(thunk)))

//数据持久化
export default persistStore(store)